#pragma once

#ifndef SAFE_DELETE
#define SAFE_DELETE(p) { if (p) delete (p); (p) = 0; }
#define SAFE_DELETE_ARR(p) { if (p) delete [] (p); (p) = 0; }
#endif

//-------------------------------------------------------------------------------------------------
// class for getting information from disk, memory or something else
//-------------------------------------------------------------------------------------------------

class cDataManager
{
public:
	//-------------------------------------------------------------------------------------------------
	// all errors, which can generate Data Manager

	struct cError
	{
		enum {
			Ok = 0,					// no errors. full all right.
			UnknownFormat = 1,		// unknown data format or unknown content of file
			FileNotFound = 2,		// file not found - catch error from File Manager
			InternalError = 3		// corrupt file, or internal error in Data Manager
		};
	};

	//-------------------------------------------------------------------
	// information about readed image

	// data color format (such as number of channels can be concuring)
	enum eColorType 
	{
		e_Unknown = 0,		// unknown format ( may be palleted or other )
		e_Gray = 1,			// grayscale ( one byte for each pixel )
		e_Gray_Alpha = 2,	// grayscale with alpha channel
		e_RGB = 3,			// RGB
		e_RGB_Alpha = 4		// RGBA
	};

	// information about picture
	struct cImage
	{
		unsigned char	*pData;		// buffer for pixel data ( !!!need to delete with macros SAFE_DELETE_ARR!!! )
		int				iWidth;		// image width
		int				iHeight;	// image height
		eColorType		ColorType;	// color format
	};

protected:

	//-------------------------------------------------------------------
	// functions for reading different formats of images

	// read PNG file format (png.cpp)
	int ReadPNG(cImage* pImage, const char* szFileName, const char* szZipName);
	// read JPEG file format (jpeg.cpp)
	int ReadJPEG(cImage* pImage, const char* szFileName, const char* szZipName);

public:

	//-------------------------------------------------------------------
	// read image from file. you must free pixel data, after finish using pImage
	int ReadImage(cImage* pImage, const char* szFileName, const char* szZipName);
};